package com.nali.dal.statement.query;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class DivideSelecter extends InstantSelecter {
	private DataDivider divider;
	private boolean preTran;

	public DataDivider getDivider() {
		return divider;
	}

	public void setDivider(DataDivider divider) {
		this.divider = divider;
		preTran = divider.isPreTran();
	}

	@Override
	protected List<Map<String, Object>> tranQueryRlts(List<Map<String, Object>> queryRlts, Traner traner) {
		List<Map<String, Object>> rlts = new ArrayList<Map<String,Object>>(queryRlts.size()*4/3);
		if(preTran) {
			for (Map<String,Object> queryRlt : queryRlts) {
				List<Map<String, Object>> divideRlts = divider.divide(queryRlt);
				if(divideRlts==null) {
					rlts.add(traner.tran(queryRlt));
				} else {
					for (Map<String, Object> divideRlt : divideRlts) {
						rlts.add(traner.tran(divideRlt));
					}
				}
			}
		} else {
			for (Map<String,Object> queryRlt : queryRlts) {
				Map<String, Object> tranRlt = traner.tran(queryRlt);
				List<Map<String, Object>> divideRlts = divider.divide(tranRlt);
				if(divideRlts==null) {
					rlts.add(tranRlt);
				} else {
					for (Map<String, Object> divideRlt : divideRlts) {
						rlts.add(divideRlt);
					}
				}
			}
		}
		return rlts ;
	}
}
